import request from "@/utils/request";

enum Api {
  list = "/buss/bridge/list",
  save = "/buss/bridge/add",
  edit = "/buss/bridge/edit",
  get = "/buss/bridge/queryById",
  delete = "/buss/bridge/delete",
  deleteBatch = "/buss/bridge/deleteBatch",
  exportWord = "buss/bridgeValue/exportWord",
}

/**
 * 查询列表
 * @param params
 */
export const getBridgeList = (params) => {
  return request({
    url: Api.list,
    method: "get",
    params,
  });
};

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateBridge = (data, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return request({
    url: url,
    method: "post",
    data,
  });
};

/**
 * 查询详情
 * @param params
 */
export const getBridgeById = (params) => {
  return request({
    url: Api.get,
    method: "get",
    params,
  });
};

/**
 * 单条删除
 * @param params
 */
export const deleteBridge = (params, handleSuccess) => {
  return request({
    url: Api.delete,
    method: "delete",
    params,
  }).then(() => {
    handleSuccess();
  });
};

/**
 * 导出生成的报告
 * @param params
 */
export const exportWord = (params) => {
  return request({
    url: Api.exportWord,
    method: "post",
    params,
    responseType: "blob",
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchDeleteBridge = (params, handleSuccess) => {
  ElMessageBox.confirm("确定注销并退出系统吗？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    lockScroll: false,
  }).then(() => {
    return request({
      url: Api.deleteBatch,
      method: "delete",
      params,
    });
  });
};
